package test;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author raok
 * @create 2022-04-26-21:54
 **/
public class test {
    String path="./";
    @Test
    public void excel03Test() throws IOException {

        Workbook work = new SXSSFWorkbook();//创建一个工作簿03 HSSF;07 XSSF
        Sheet sheet = work.createSheet("页签1");//创建一个工作表
        Row row = sheet.createRow(0);//创建一行
        Cell cell0 = row.createCell(0);//创建一个单元格
        cell0.setCellValue("112");//写入内容
        Cell cell11 = row.createCell(1);//再创建一个单元格
        cell11.setCellValue("112");//写入内容

        FileOutputStream fileOutputStream = new FileOutputStream(path + "12.xlsx"); //07是xlsx(XSFX/SXSFX)
        work.write(fileOutputStream);//生成一张表
        fileOutputStream.close();

        cell0.getCellTypeEnum();
        //清除SXXSF的临时文件
        ((SXSSFWorkbook)work).dispose();
        System.out.println("输出完成");
    }
}
